#!/bin/bash

CURRENT_DIR=$(
   cd "$(dirname "$0")"
   pwd
)

echo ${CURRENT_DIR}

function log() {
   message="[PLM Log]: $1 "
   echo -e "${message}" 2>&1 | tee -a ${CURRENT_DIR}/install.log
}

log "========1.安装docker========"
echo "兼容centos8"
dnf remove podman
yum -y erase podman buildah
# 卸载旧版本
yum remove -y docker \
docker-client \
docker-client-latest \
docker-ce-cli \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-selinux \
docker-engine-selinux \
docker-engine
log "========添加阿里云镜像加速器============="

mkdir -p ${CURRENT_DIR}/docker

echo "========安装gcc============"
 yum -y install gcc
echo “===========安装gcc-c++=============”
yum -y install gcc-c++
gcc -v
echo "=============安装需要的软件包=================="
 yum install -y yum-utils device-mapper-persistent-data lvm2
echo "==================设置stable镜像仓库========================"
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
echo "======================更新yum软件包索引==============================="
yum makecache fast
echo "=======================安装docker ce=============================="
yum -y install docker-ce

echo "===============查看docker版本==========================="

docker_version_install_success=`docker version`
if [ $"docker_version_install_success" ]
then
        log "docker已经成功安装"
else
        log "docker未安装成功,请检查执行过程"
        exit
fi
source /etc/docker/daemon.json
cat > /etc/docker/daemon.json <<EOF
{
  "registry-mirrors": ["https://registry.cn-hangzhou.aliyuncs.com"] ,
  "data-root": "${CURRENT_DIR}/docker",
  "log-driver":"json-file",
  "log-opts": {"max-size":"100m", "max-file":"1"}
}
EOF
systemctl enable docker.service
service docker start
log "========2.安装docker-compose========"
echo "开始安装docker-compose(国内源)"
curl -L https://get.daocloud.io/docker/compose/releases/download/1.23.2/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/curl -L https://get.daocloud.io/docker/compose/releases/download/1.23.2/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
docker_compose_install_success=`docker-compose -v|grep -o version`
if [ $"$docker_compose_install_success" ]
then
        log "docker-compose已经成功安装"
else
        log "docker-compose未安装成功,请检查执行过程"
        exit
fi
